home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / fweb / fweb-1.40 / manual / f_to_web.web < prev    next >
Text File  |  1993-10-29  |  3KB  |  102 lines

  1. @z --- f_to_web.web ---
  2.  
  3. This file is part of FWEB.  It and its various pieces of processed output are
  4. included into the user manual fwebman.tex.
  5.  
  6. Author:  J. A. Krommes
  7. Version: 1.23
  8. Date:    April 1, 1992
  9.  
  10. @x-----------------------------------------------------------------------------
  11.  
  12. @n/ @% Set the language to Fortran, and allow short comments.
  13.  
  14. \def\title{--- F\_TO\_WEB ---}
  15.  
  16. @* INTRODUCTION. This demo shows you how to convert the file
  17. \.{f\_to\_web.src} (look at that file with your editor now) into a valid
  18. \.{FWEB} file, namely this file \.{f\_to\_web.web}. Each subroutine should
  19. be placed into a separate module, begun with~`\.{@@*}' or~`\.{@@\ }'. After
  20. those symbols, you should explain what the subroutine does, using \TeX\ in
  21. all its glory. Then follows the code, introduced by~`\.{@@a}' or
  22. `\.{@@<...@@>=}'. Code sections should be short---about 12 lines, according
  23. to Knuth. If they're too long, break them up into named fragments that are
  24. explained separately. For new code, comments should be C-style---namely,
  25. ``\.{/*...*/}'' or ``\.{//...}''.  (In order to use the latter form, you
  26. must use the command-line option~`\.{-n/}', and then you must use the
  27. symbol~`\.{\\/}' for concatenation.)
  28.  
  29. Before proceeding, let us note that standard Fortran is {\it not}
  30. recommended for new code. Use the Ratfor mode instead. Standard Fortran
  31. mode is intended primarily to support conversion of existing code.
  32.  
  33. Notice how forward references to named modules and function names are
  34. handled in the woven output.
  35. @a
  36.         program main
  37.         @<Common blocks@>
  38.  
  39. /* Initialize values.  Long comments should be done in standard
  40. C style and may be continued across lines.  */
  41.         x = -3.14159e-11
  42.         i = 1
  43.  
  44.         call see  // Print results.  (Short comments can be done like this.)
  45.  
  46.         end
  47.  
  48. @ Code fragments can be defined anywhere, even after they are used.
  49.  
  50. @f @<Com...@> common /* Use a format statement to tell \.{WEAVE} how to handle
  51.             this module name. */
  52.  
  53. @<Com...@>=
  54.         integer i
  55.         real x
  56.         common/test/ x,i
  57.  
  58. @ Notice how the common block information is handled. You don't need to
  59. include such stuff from a separate file.
  60.  
  61. @M NFMT #:0 /* This preprocessor command is a handy way of replacing numeric
  62.     statement labels by symbolic ones. Numeric statement labels will
  63.     never have to be used. */
  64.  
  65. @a
  66.         subroutine see
  67.         @<Com...@> /* You can abbreviate the name if it has already
  68.  appeared in full. */
  69.  
  70.         write(6,NFMT) x,i
  71. NFMT:   format(' x = ',1pe10.2,', i = ',i2)
  72.         return
  73.         end
  74.  
  75. @ In fact, the Ratfor language is recommended for new Fortran codes. It's
  76. best to do everything in Ratfor, but you can also work on a
  77. module-by-module basis. Here's an example. Examine the listing of the
  78. output file in Appendix~D to see how this is translated into standard
  79. Fortran.
  80.  
  81. @a
  82. @r/ @%* Set the language to Ratfor-77, for this section only. */
  83. integer function f(a,b,n)
  84.         integer n;
  85.         real a(0:n-1),b(0:n-1);
  86. {
  87. integer k;
  88.  
  89. /* You can (and should) use a |do| loop for the following, but the |for|
  90. construction is more flexible in general, so we use it to demonstrate. */
  91. for(k=0; k<n; k++)
  92.         {
  93.         a(k) = k;
  94.         b(k) = k^2; /* In Ratfor and Fortran, you can use pretty
  95. alternatives for archaic Fortran constructions such as~\.{.lt.} or~\.{**}. */
  96.         }
  97.  
  98. return n;  // It's easy to return values from functions.
  99. }
  100.  
  101. @* INDEX.
  102.